/*
 * MIPS_1 R3000 mini-monitor
 *
 * simplified version, the following are excluded:
 *
 *  - aliases for general registers 
 *  - System Control Coprocessor (CP0) registers
 *  - Floating-Point Control registers
 *  - Status Register
 *  - Cause Register
 *  - Exception Code
 *  - FPU stuff 
 *  - Config Register 
 *  - Primary cache mode
 *  - Primary Cache TagLo 
 *  - CacheErr register
 *  - Cache operations
 *  - Watchpoint Register 
 */



   .section   .text
   .text
   .align 2
   .global mini_mon
   .global main

mini_moon:
main:   


 /*
  * Initialize UART baud rate, set to N,8,2
  */


        # n.a.

 /*
  * Atlas board, yamon specific
  */


        la      $4,p_mon_exit           # saving address of yamon monitor
        sw      $16,0($4)

 /*
  * Initialize things and doing banner
  */

	la	$4,banner		# write our banner
	jal	outstr
	nop

	la	$17,inbuf		# init input buffer pointer
	la	$18,inbufptr
	sw	$17,0($18)

 /*
  * command interpreter
  */
  
cmd_interpreter:
	li	$4,'>'
	jal	putchar
	nop

	jal	getline
	nop

	jal	skip_ws
	nop

	la	$8,inbufptr		# get input buffer pointer in $9
	lw	$9,0($8)
	nop

	lbu	$10,0($9)		# get char in $10
	nop

	addi	$9,$9,1			# advance input buffer pointer
	sw	$9,0($8)

	beq	$10,13,cmd_interpreter	# null command is OK
	nop

	beq	$10,'?',help_cmd
	nop

	beq	$10,'q',quit_cmd
	nop

	beq	$10,'c',dump_code_cmd
	nop

	beq	$10,'d',dump_data_cmd
	nop

	beq	$10,'t',test_cmd
	nop

	beq	$10,'h',help_cmd
	nop

	beq	$10,'d',dump_cmd
	nop

	beq	$10,'s',set_cmd
	nop

	beq	$10,'f',fill_cmd		# fill commands
	nop

	beq	$10,'l',load_cmd
	nop

	beq	$10,'g',go_cmd
	nop

badcmd:	li	$4,'?'
	jal	putchar
	nop

	li	$4,13
	jal	putchar
	nop

	li	$4,10
	jal	putchar
	nop

	j	cmd_interpreter
	nop


/*
 * help command
 */

help_cmd:
	la	$4,help_msg
	jal	outstr
	nop

	j	cmd_interpreter
	nop

quit_cmd:
        la      $4,p_mon_exit           # loading address of yamon monitor
        lw      $16,0($4)

        jr      $16                     # going back to yamon
        nop

	j	cmd_interpreter         # it should never happen
	nop



/*
 * load command - download S-records
 *
 * register usage:
 *   s0:  S-record type (ascii char, '3' or '7')
 *   s1:  S-record length
 *   s2:  S-record address
 *   s3:  S-record running checksum
 */

load_cmd:
	la	$4,load_msg
	jal	outstr
	nop

find_s:	
        li	$19,0			# init checksum

	jal	getchar			# listen for S
	nop
        
        move    $4,$2                   # echo it
	jal	putchar			
	nop

	beq	$4,'.',load_int		# interrupt?
	nop
	beq	$2,3,load_int		# interrupt?
	nop

	bne	$2,'S',find_s
	nop

	jal	getchar			# get record type
	nop

        move    $4,$2                   # echo it
	jal	putchar			
	nop

	beq	$2,3,load_int		# interrupt?
	nop
	beq	$2,'.',load_int		# interrupt?
	nop

	beq	$2,'3',load_s3
	nop

	beq	$2,'7',load_s7
	nop

	j	load_bad_srec
	nop

load_s3:
# get length into $17 - must be at least 5
	la	$4,load_bad_digit	# get length - must be 5
	la	$5,load_int
	jal	inbyte
	nop
	blt	$2,5,load_bad_len
	nop

	addi	$17,$2,-5

# get four bytes of address into $18
	jal	inbyte
	nop
	move	$18,$2
	jal	inbyte
	nop
	sll	$18,$18,8
	or	$18,$18,$2
	jal	inbyte
	nop
	sll	$18,$18,8
	or	$18,$18,$2
	jal	inbyte
	nop
	sll	$18,$18,8
	or	$18,$18,$2

# get and store data bytes

load_byte:
	jal	inbyte
	nop
	sb	$2,0($18)
	addi	$18,$18,1			# increment address
	addi	$17,$17,-1		# decrement byte count
	bnez	$17,load_byte
	nop	

# get checksum
	jal	inbyte
	nop

# test checksum
	andi	$19,$19,255
	bne	$19,255,load_bad_cksm
	nop

# loop for more
	j	find_s
	nop


load_s7:
	la	$4,load_bad_digit	# get length - must be 5
	la	$5,load_int
	jal	inbyte
	nop
	bne	$2,5,load_bad_len
	nop

# get four bytes of address
	jal	inbyte
	nop
	move	$18,$2
	jal	inbyte
	nop
	sll	$18,$18,8
	or	$18,$18,$2
	jal	inbyte
	nop
	sll	$18,$18,8
	or	$18,$18,$2
	jal	inbyte
	nop
	sll	$18,$18,8
	or	$18,$18,$2

	la	$2,go_addr		# save for go command
	sw	$18,0($2)

# get checksum
	jal	inbyte
	nop

# test checksum
	andi	$19,$19,255
	bne	$19,255,load_bad_cksm
	nop

# return to cmd_interpreter
	j	cmd_interpreter
	nop


load_bad_digit:
	la	$4,load_bad_digit_msg
	jal	outstr
	nop

	j	cmd_interpreter
	nop
	
load_bad_len:
	la	$4,load_bad_len_msg
	jal	outstr
	nop

	j	cmd_interpreter
	nop
	
load_bad_srec:
	la	$4,load_bad_srec_msg
	jal	outstr
	nop

	j	cmd_interpreter
	nop
	
load_bad_cksm:
	la	$4,load_bad_cksm_msg
	jal	outstr
	nop

	j	cmd_interpreter
	nop
	
load_int:
	la	$4,load_int_msg
	jal	outstr
	nop
	
	j	cmd_interpreter
	nop


/*
 * inbyte - input a hexadecimal byte (without echo) and return it in v0
 *
 * input -  a0 = address to jump to if bad hex digit found
 *          a1 = address to jump to if user interrupt (control-C)
 *          s3 = previous running checksum
 * output - v0 = data byte
 *          s3 = updated running checksum
 * uses   - t0 - used by getchar
 *          t1 - used by getchar
 *          t2 - value of first digit * 16
 *          t3 = saved return address
 */

inbyte:
	move	$11,$31

	jal	getchar
	nop

	beq	$2,3,inb_int
	nop

	blt	$2,'0',inb_bd
	nop

	bgt	$2,'9',inb_nn1
	nop

	addi	$10,$2,-'0'
	j	inb_d2
	nop

inb_nn1:
	blt	$2,'A',inb_bd
	nop

	bgt	$2,'F',inb_bd
	nop

	addi	$10,$2,10-'A'

inb_d2:
	sll	$10,$10,4

	jal	getchar
	nop

	beq	$2,3,inb_int
	nop

	blt	$2,'0',inb_bd
	nop

	bgt	$2,'9',inb_nn2
	nop

	addi	$2,$2,-'0'
	j	inb_9
	nop

inb_nn2:
	blt	$2,'A',inb_bd
	nop

	bgt	$2,'F',inb_bd
	nop

	addi	$2,$2,10-'A'

inb_9:
	add	$2,$2,$10
	add	$19,$19,$2
	j	$11
	nop

inb_bd:	
	j	$4
	nop

inb_int:
	j	$5
	nop



/*
 * go command
 */

go_cmd:
	jal	skip_ws
	nop

	la	$8,inbufptr		# get input buffer pointer in $9
	lw	$9,0($8)
	nop

	lbu	$10,0($9)		# get char
	nop

	beq	$10,13,go_now		# if it is a CR, don't get 2nd address
	nop

	beq	$10,10,go_now		# if it is a LF, don't get 2nd address
	nop

	jal	parse_hex		# get address from command line
	nop

	la	$11,go_addr		# save address
	sw	$2,0($11)

go_now:	la	$11,go_addr		# get address
	lw	$2,0($11)
	nop

	jal	$2			# call it
	nop

	j	cmd_interpreter	        # it might return
	nop


/*
 * test
 */

test_cmd:
        # parse hexadecimal input, return in $2
	jal	skip_ws
        nop
	jal	parse_hex		# get first address
        nop
	move	$4,$2

        # output a hex word from $4
        jal outhexw
        nop

	li	$4,13			# output CRLF
	jal	putchar
	nop

	li	$4,10
	jal	putchar
	nop

	j	cmd_interpreter
	nop

dump_code_cmd:
        # dump memory from $4 to $5
        # $6: size (1, 2, 4)
        #
        la      $4, code_begin
        la      $5, code_end
        nop
        #move    $5, $4
	#addiu	$5, 128
        nop
        la      $6, 0x4   # dump as uint32
        nop
        jal     dump 
        nop
	j	cmd_interpreter
	nop

dump_data_cmd:
        # dump memory from $4 to $5
        # $6: size (1, 2, 4)
        #
        la      $4, data_begin
        la      $5, data_end
        nop
        #move    $5, $4
	#addiu	$5, 128
        nop
        la      $6, 0x1   # dump as uint8
        nop
        jal     dump 
        nop
	j	cmd_interpreter
	nop


/*
 * Dump a block of memory
 */

dump_cmd:
	lbu	$10,0($9)		# get char in $10
	nop

	addi	$9,$9,1			# advance input buffer pointer
	sw	$9,0($8)

	li	$6,1			# bytes
#######################################################################
        #j       d_cmd_1                # forcing byte
        #nop
#######################################################################
	beq	$10,' ',d_cmd_1
	nop

	beq	$10,'b',d_cmd_1
	nop

	li	$6,2			# half-words
	beq	$10,'h',d_cmd_1
	nop

	li	$6,4			# words
	beq	$10,'w',d_cmd_1
	nop

	j	badcmd
	nop

d_cmd_1:
	jal	skip_ws
	nop

	jal	parse_hex		# get first address
	nop
	move	$4,$2

	jal	skip_ws
	nop

	li	$5,128			# default to dumping 128 bytes
	add	$5,$5,$4

	la	$8,inbufptr		# get input buffer pointer in $9
        nop
	lw	$9,0($8)
	nop

	lbu	$10,0($9)		# get char
	nop

	beq	$10,13,dumpit		# if it is a CR, don't get 2nd address
	nop

	beq	$10,10,dumpit		# if it is a LF, don't get 2nd address
	nop

	jal	parse_hex		# get 2nd address
	nop
##########################################################################################
	move	$5,$2                   # used as second address
##########################################################################################

dumpit:	
        jal	dump
	nop

	j	cmd_interpreter
	nop


/* fill commands */

fill_cmd:
	lbu	$10,0($9)		# get char in $10
	nop

	addi	$9,$9,1			# advance input buffer pointer
	sw	$9,0($8)

	beq	$10,'b',fb_cmd
	nop

	beq	$10,'h',fh_cmd
	nop

	beq	$10,'w',fw_cmd
	nop

	j	badcmd
	nop

fb_cmd:
	jal	skip_ws			# get address 1 in $16
	nop
	jal	parse_hex
	nop
	move	$16,$2

	jal	skip_ws			# get address 2 in $17
	nop
	jal	parse_hex
	nop
	move	$17,$2

	jal	skip_ws			# get data in $17
	nop
	jal	parse_hex
	nop
	move	$18,$2

fb_loop:
	sb	$18,0($16)
	addi	$16,$16,1
	blt	$16,$17,fb_loop
	nop
	j	cmd_interpreter
	nop


fh_cmd:
	jal	skip_ws			# get address 1 in $16
	nop
	jal	parse_hex
	nop
	move	$16,$2

	jal	skip_ws			# get address 2 in $17
	nop
	jal	parse_hex
	nop
	move	$17,$2

	jal	skip_ws			# get data in $17
	nop
	jal	parse_hex
	nop
	move	$18,$2

fh_loop:
	sh	$18,0($16)
	addi	$16,$16,2
	blt	$16,$17,fh_loop
	nop
	j	cmd_interpreter
	nop
	

fw_cmd:
	jal	skip_ws			# get address 1 in $16
	nop
	jal	parse_hex
	nop
	move	$16,$2

	jal	skip_ws			# get address 2 in $17
	nop
	jal	parse_hex
	nop
	move	$17,$2

	jal	skip_ws			# get data in $17
	nop
	jal	parse_hex
	nop
	move	$18,$2

fw_loop:
	sw	$18,0($16)
	addi	$16,$16,4
	blt	$16,$17,fw_loop
	nop
	j	cmd_interpreter
	nop
	


set_cmd:
	lbu	$10,0($9)		# get char in $10
	nop

	addi	$9,$9,1			# advance input buffer pointer
	sw	$9,0($8)

	beq	$10,'b',sb_cmd
	nop

	beq	$10,'h',sh_cmd
	nop

	beq	$10,'w',sw_cmd
	nop

	j	badcmd
	nop


sb_cmd:
	jal	skip_ws			# get address in $16
	nop
	jal	parse_hex
	nop
	move	$16,$2

sb0:	jal	skip_ws			# get data in $17
	nop

	la	$8,inbufptr		# get input buffer pointer in $9
	lw	$9,0($8)
	nop

	lbu	$10,0($9)		# get char in $10
	nop

	beq	$10,13,cmd_interpreter	# if CR, done
	nop

	jal	parse_hex
	nop
	move	$17,$2

	sb	$17,0($16)		# store the byte
	addi	$16,$16,1			# advance

	j	sb0
	nop


sh_cmd:
	jal	skip_ws			# get address in $16
	nop
	jal	parse_hex
	nop
	move	$16,$2

sh0:	jal	skip_ws			# get data in $17
	nop

	la	$8,inbufptr		# get input buffer pointer in $9
	lw	$9,0($8)
	nop

	lbu	$10,0($9)		# get char in $10
	nop

	beq	$10,13,cmd_interpreter	# if CR, done
	nop

	jal	parse_hex
	nop
	move	$17,$2

	sh	$17,0($16)		# store the half-word
	addi	$16,$16,2		# advance

	j	sh0
	nop


sw_cmd:
	lbu	$10,0($9)		# get char in $10
	nop

	addi	$9,$9,1			# advance input buffer pointer
	sw	$9,0($8)

	beq	$10,'l',swl_cmd
	nop

	beq	$10,'r',swr_cmd
	nop

	jal	skip_ws			# get address in $16
	nop
	jal	parse_hex
	nop
	move	$16,$2

sw0:	jal	skip_ws			# get data in $17
	nop

	la	$8,inbufptr		# get input buffer pointer in $9
	lw	$9,0($8)
	nop

	lbu	$10,0($9)		# get char in $10
	nop

	beq	$10,13,cmd_interpreter	# if CR, done
	nop

	jal	parse_hex
	nop
	move	$17,$2

	sw	$17,0($16)		# store the word
	addi	$16,$16,4		# advance

	j	sw0
	nop

swl_cmd:
	jal	skip_ws			# get address in $16
	nop
	jal	parse_hex
	nop
	move	$16,$2

	jal	skip_ws			# get data in $17
	nop
	jal	parse_hex
	nop
	move	$17,$2

	swl	$17,0($16)		# store the word

	j	cmd_interpreter
	nop

swr_cmd:
	jal	skip_ws			# get address in $16
	nop
	jal	parse_hex
	nop
	move	$16,$2

	jal	skip_ws			# get data in $17
	nop
	jal	parse_hex
	nop
	move	$17,$2

	swr	$17,0($16)		# store the word

	j	cmd_interpreter
	nop




# dump memory from $4 to $5
# $6: size (1, 2, 4)

dump:
	move	$16,$4			# $$$ need to save $16...$19 on stack
	move	$17,$5
	move	$18,$31

dump0:	move	$4,$16			# output address
	jal	outhexw
	nop

	li	$4,':'
	jal	putchar
	nop

	li	$19,16			# init line byte counter

dump1:	
        li	$4,' '			# output data
	jal	putchar
	nop

	beq	$6,1,dump_byte
	nop

	beq	$6,2,dump_half
	nop

	beq	$6,4,dump_word
	nop

	li	$6,1			# should never happen, but try to
					# fix it up

dump_byte:
	lbu	$4,0($16)
	jal	outhexb
	nop
	j	dump_8
	nop

dump_half:
	lhu	$4,0($16)
	jal	outhexh
	nop
	j	dump_8
	nop

dump_word:
	lw	$4,0($16)
	jal	outhexw
	nop
	j	dump_8
	nop

dump_8:	addu	$16,$16,$6		# increment address
	subu	$19,$19,$6		# decrement line byte counter

	bne	$19,0,dump1		# more bytes this line?
	nop

	li	$4,13			# output CRLF
	jal	putchar
	nop

	li	$4,10
	jal	putchar
	nop

        ############################################
	#bnez	$2,dump9      wft is this used for?
	#nop                  not working with this
        ############################################

######################################################################
	blt	$16,$17,dump0		# more bytes?
	nop
######################################################################

dump9:	
        j	$18			# return
	nop


# skip whitespace
# uses $8,$9,$10

skip_ws:
	la	$8,inbufptr		# get input buffer pointer in $9
	lw	$9,0($8)
	nop

skipw0:	lbu	$10,0($9)		# get char
	nop

	beq	$10,32,skipw1		# space?
	nop

	beq	$10,8,skipw1		# tab?
	nop

	sw	$9,0($8)		# save buffer pointer
	j	$31
	nop

skipw1:	addi	$9,$9,1			# advance input buffer pointer
	j	skipw0
	nop



# parse hexadecimal input, return in $2

parse_hex:
	li	$2,0

	la	$8,inbufptr		# get input buffer pointer in $9
	nop
	lw	$9,0($8)
	nop

ph0:	
        lbu	$10,0($9)		# get char in $10
	nop
	
	blt	$10,'0',notnum
	nop
	bgt	$10,'9',notnum
	nop

	addi	$10,$10,-'0'
	j	gotdigit
	nop

notnum:	
        blt	$10,'a',notlc
	nop
	bgt	$10,'f',notlc
	nop

	addi	$10,$10,10-'a'

gotdigit:
	sll	$2,$2,4
	add	$2,$2,$10

	addi	$9,$9,1			# advance input buffer pointer

	j	ph0			# get some more
	nop

notlc:	
        sw	$9,0($8)		# store input buffer pointer

	j	$31
	nop


# output a string from $4

outstr:	
        move	$15,$31
	move	$14,$4

outs0:	
        lbu	$4,0($14)		# get byte
	addi	$14,$14,1

	beqz	$4,outs9
	nop

	jal	putchar
	nop

	j	outs0
	nop

outs9:	j	$15
	nop



# output a hex word from $4

outhexw:
	move	$15,$31
	move	$14,$4

	srl	$4,$14,28
	jal	outhexd
	nop

	srl	$4,$14,24
	jal	outhexd
	nop

	srl	$4,$14,20
	jal	outhexd
	nop

	srl	$4,$14,16
	jal	outhexd
	nop

	srl	$4,$14,12
	jal	outhexd
	nop

	srl	$4,$14,8
	jal	outhexd
	nop

	srl	$4,$14,4
	jal	outhexd
	nop

	move	$4,$14
	move	$31,$15

	j	outhexd
	nop


# output a hex half-word from $4

outhexh:
	move	$15,$31
	move	$14,$4

	srl	$4,$14,12
	jal	outhexd
	nop

	srl	$4,$14,8
	jal	outhexd
	nop

	srl	$4,$14,4
	jal	outhexd
	nop

	move	$4,$14
	move	$31,$15

	j	outhexd
	nop


# output a hex byte from $4

outhexb:
	move	$15,$31
	move	$14,$4

	srl	$4,$14,4
	jal	outhexd
	nop

	move	$4,$14
	move	$31,$15

# fall into outhexd


# output a hex digit from $4

outhexd:
	andi	$4,$4,15

	blt	$4,10,lt9
	nop

	addi	$4,$4,7

lt9:	addi	$4,$4,48
        
        j       putchar
        nop



# get a line of input
# use: $16 - save return address
#      $17 - buffer pointer
#      $18 - temp

getline:
	move	$16,$31			# save return address

	la	$17,inbuf		# init input buffer pointer
	la	$18,inbufptr
	sw	$17,0($18)

gl0:	jal	getchar			# get a character
	nop

	andi	$2,$2,127		# mask off high bit

	beq	$2,8,glbs		# handle backspace
	nop

	beq	$2,127,glbs		# handle rubout like backspace
	nop

	sb	$2,0($17)		# store it in the buffer
	addi	$17,$17,1
	move	$4,$2			# echo it
	jal	putchar
	nop
	bne	$2,13,gl0		# if not a CR, get some more
	nop

	li	$4,10			# output an LF
	jal	putchar
	nop

glcr:	j	$16			# return
	nop

glbs:	la	$18,inbuf		# if at beginning of buffer, do
	beq	$17,$18,gl0		#   nothing
	nop

	li	$4,8			# echo BS
	jal	putchar
	nop

	li	$4,32			# echo space
	jal	putchar
	nop

	li	$4,8			# echo BS
	jal	putchar
	nop

	addi	$17,$17,-1		# back up
	j	gl0
	nop


/*
ret:	li	v0,0
	j	ra
*/

print:	move	$15,$31
	move	$14,$5

print0:	lbu	$4,0($14)		# get byte
	addi	$14,$14,1

	beqz	$4,print9
	nop

	jal	putchar
        nop

        j	print0
        nop

print9:	j	$15
	nop

print_count:
	move	$15,$31
	move	$14,$5
	move	$24,$6			# count

prc0:	lbu	$4,0($14)		# get byte
	jal	putchar
	nop
	addi	$14,$14,1
	addi	$24,$24,-1
	bnez	$24,prc0
	nop

	j	$15



################################################################################    
   
   .section   .data
   .data

play_area:	.space	128
go_addr:	.space	4
inbufptr:	.space	4
inbuf:	        .space	128
p_mon_exit:     .space  4    

banner:
	.byte	13,10
	.ascii	"mips mini mon v2.1"
	.byte	13,10
	.byte	0

crlf_msg:
	.byte	13,10,0

help_msg:
	.ascii	"Commands:"
	.byte	13,10,13,10
	.ascii	"db <addr1> [<addr2>]       dump bytes from addr1 to addr2"
	.byte	13,10
	.ascii	"dh <addr1> [<addr2>]       dump half-words (16 bits)"
	.byte	13,10
	.ascii	"dw <addr1> [<addr2>]       dump words (32 bits)"
	.byte	13,10
	.ascii	"c                          dump code space (32 bits)"
	.byte	13,10
	.ascii	"d                          dump data space (8 bits)"
	.byte	13,10
	.ascii	"sb <addr> <data>...        store byte"
	.byte	13,10
	.ascii	"sh <addr> <data>...        store half-word (16 bits)"
	.byte	13,10
	.ascii	"sw <addr> <data>...        store word (32 bits)"
	.byte	13,10
	.ascii	"swl <addr> <data>          store word left"
	.byte	13,10
	.ascii	"swr <addr> <data>          store word right"
	.byte	13,10
	.ascii	"fb <addr1> <addr2> <data>  fill bytes of memory range"
	.byte	13,10
	.ascii	"fh <addr1> <addr2> <data>  fill half-words"
	.byte	13,10
	.ascii	"fw <addr1> <addr2> <data>  fill words"
	.byte	13,10
	.ascii	"l                          load S-records"
	.byte	13,10
	.ascii	"g [<addr>]                 go (start execution at address)"
	.byte	13,10
	.ascii	"q                          quit (return to yamon)"
	.byte	13,10,0
	.ascii	"h                          help (show this command list)"
	.byte	13,10,0

load_msg:
	.ascii	"Start S-record download now, or control-C to abort."
	.byte	13,10,0

load_int_msg:
	.ascii	"S-record download aborted by user."
	.byte	13,10,0

load_bad_srec_msg:
	.ascii	"S-record type unrecognized, download aborted."
	.byte	13,10,0

load_bad_len_msg:
	.ascii	"bad S-record length, download aborted."
	.byte	13,10,0

load_bad_digit_msg:
	.ascii	"bad hex digit in S-record, download aborted."
	.byte	13,10,0

load_bad_cksm_msg:
	.ascii	"bad checksum in S-record, download aborted."
	.byte	13,10,0

manuf_msg:
	.ascii	"manufacturer: "
	.byte	0

dev_msg:	
	.byte	13,10
	.ascii	"      device: "
	.byte	0

sect_prot_msg:
	.byte	13,10
	.ascii	" sector prot: "
	.byte	0

gen_exc_msg:
	.byte	13,10
	.ascii	"General"
	.byte	0

exc_msg0:
	.ascii	" exception!"
	.byte	0

exc_cause_msg:
	.byte	13,10
	.ascii	"Cause:    "
	.byte	0

exc_pc_msg:
	.byte	13,10
	.ascii	"PC:       "
	.byte	0

exc_epc_msg:
	.byte	13,10
	.ascii	"EPC:      "
	.byte	0

exc_stat_msg:
	.byte	13,10
	.ascii	"Status:   "
	.byte	0

exc_badaddr_msg:
	.byte	13,10
	.ascii	"Bad Addr: "
	.byte	0

exc_ctx_msg:
	.byte	13,10
	.ascii	"Context:  "
	.byte	0

exc_xctx_msg:
	.byte	13,10
	.ascii	"XContext: "
	.byte	0

exc_msg9:
	.byte	13,10,0
